package com.vodone.v1pin.video.delegate
{
	import flash.utils.Timer;

	public class TimeUtil
	{
		/**
		 * 格式化时间的显示 24小时之内的显示 时分秒 之外的显示原时间刻度
		 * */
		public static function getTimeFormatShow(time:Number,nowTime:Number):String
		{
			if(isNaN(time) || isNaN(nowTime) || nowTime == 0)return "刚刚";
			if(time < nowTime && (nowTime - time ) < 86400000 )
			{
				return getTimeStr_HH_MM(nowTime - time);
			}
			else if(time >= nowTime)
			{
				return "刚刚";
			}
			return getTimeStr_more( time );
		}
		/**
		 * 格式化时间的 显示规则
		 * */
		public static function getTimeStr_HH_MM(value:Number):String
		{
			var result:String = "";
			if(!isNaN(value) && value > 0 )
			{
				var day:int = value / 86400000;
				var hour:int = (value - day * 86400000) / 3600000;
				var minute:int = (value - day * 86400000 - hour * 3600000)/60000;
				if(minute > 0)
				{
					result += minute + "分钟前";
				}
				if(hour > 0)
				{
					result = hour + "小时" + result;
				}
				if(day > 0)
				{
					result = day + "天" + result;
				}
			}
			return result == "" ? "刚刚" : result;
		}
		
		/**
		 * 根据从1970.1.1日起的毫秒数，返回一个时间字符串,格式为yyyy-mm-dd hh:mm
		 */
		public static function getTimeStr_more(time:Number):String
		{
			var date:Date = new Date(time);
			return getTimeStr(time) + " " + getTwoNumber(date.getHours()) + ":" + getTwoNumber(date.getMinutes());
		}
		/**
		 * @param time 1970.1.1日起的毫秒数
		 * @param spl 分隔符，默认为“-”
		 * @return YYYY-MM-DD格式的字符串
		 */		
		public static function getTimeStr(time:Number, spl:String = "-"):String
		{
			if( time < 0 )
			{
				return "--"
			}
			var date:Date = new Date(time);
			var month:uint = date.getMonth() + 1;
			var monthStr:String = getTwoNumber( month );
			var day:uint = date.getDate();
			var dayStr:String = getTwoNumber( day );
			return date.getFullYear() + spl + monthStr + spl + dayStr;
		}
		/**
		 * @param number 数字
		 * @return 小于10则返回前面加0的字符串，大于10则直接返回对应的字符串
		 */		
		private static function getTwoNumber(number:Number):String
		{
			return String((number >= 10) ? number : ("0" + number))
		}
		/**
		 * 计算秒杀开始的时间显示
		 * */
		public static function getTimeStr_HH_MM_SS(start:Number , end:Number , nowTime:Number , isStart:Boolean , startMsg:String , endMsg:String):String
		{
			var value:Number;
			if(isStart)
			{
				if(isNaN(end) || isNaN(nowTime) || nowTime > end)return startMsg + endMsg;
				value = end - nowTime;
			}
			else
			{
				if(isNaN(start) || isNaN(nowTime) || nowTime > start)return startMsg + endMsg;
				value= start - nowTime;
			}
			var day:int = value / 86400000;
			var hour:int = (value - day * 86400000) / 3600000;
			var minute:int = (value - day * 86400000 - hour * 3600000)/60000;
			var ss:int = (value - day * 86400000 - hour * 3600000 - minute * 60000)/1000;
			
			var result:String = "<font color='#cc0000' size='18'>" + ss + "</font>秒" + endMsg;
			if(minute > 0)
			{
				result = "<font color='#cc0000' size='18'>" + minute + "</font>分" + result;
			}
			if(hour > 0)
			{
				result = "<font color='#cc0000' size='18'>" + hour + "</font>时" + result;
			}
			if(day > 0)
			{
				result = "<font color='#cc0000' size='18'>" + day + "</font>天" + result;
			}
			return startMsg + result;
		}
		
		
	}
}